package com.lgc.webtest.mq.producer;

import com.lgc.webtest.configuration.RabbitMQConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * HelloSender发送者
 */
@Component
@Slf4j
public class HelloSender {

    //abbitTemplate是springboot 提供的默认实现
    @Autowired
    private AmqpTemplate rabbitTemplate;

    public void send(String message) {
        //rabbitTemplate.convertAndSend("test-queue1", message);
        rabbitTemplate.convertAndSend(RabbitMQConfig.DIRECT_EXCHANGE_NAME,RabbitMQConfig.ROUTING_KEY,message);
        log.info(String.format("send message: %s", message));
    }
}
